class Helper {
  get val() {
    return this.obj
  }
  constructor(title, dataIndex) {
    this.obj = {
      title,
      dataIndex
    }
  }

  Select(valueEnum) {
    this.obj.valueType = 'select'
    this.obj.valueEnum = valueEnum
    return this
  }

  Radio(valueEnum) {
    this.obj.valueType = 'radio'
    this.obj.valueEnum = valueEnum
    return this
  }

  Switch(valueEnum) {
    this.obj.valueType = 'switch'
    this.obj.valueEnum = valueEnum
    return this
  }

  Textarea() {
    this.obj.valueType = 'textarea'
    return this
  }

  Render(fn) {
    this.obj.render = fn
    return this
  }

  Digit() {
    this.obj.valueType = 'digit'
    return this
  }

  Cascader(req, others = {}) {
    this.obj.valueType = 'cascader'
    this.obj.request = req
    const old = this.obj.fieldProps || {}
    this.obj.fieldProps = Object.assign({}, old, others)

    return this
  }

  TreeSelect(req) {
    this.obj.valueType = 'treeSelect'
    this.obj.request = req
    return this
  }

  Params(params) {
    this.obj.params = params
    return this
  }
  FieldNames(names) {
    const old = this.obj.fieldProps || {}
    this.obj.fieldProps = Object.assign({}, old, {
      fieldNames: names
    })
    return this
  }
  Width(wd) {
    this.obj.width = wd
    return this
  }
  FIP(props) {
    this.obj.formItemProps = props
    return this
  }
}

Helper.Table = (title, dataIndex) => {
  return new Helper(title, dataIndex)
}

Helper.Form = (title, dataIndex) => {
  return new Helper(title, dataIndex)
}

Helper.Rule = (rules = []) => {
  return new HelperRules(rules)
}

class HelperRules {
  constructor(rules = []) {
    this.rules = rules
  }

  get val() {
    return this.rules
  }

  Add(rule) {
    this.rules.push(rule)
    return this
  }

  Require(msg) {
    this.rules.push({
      required: true,
      message: msg
    })
    return this
  }
}
export default Helper
